﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBLibrary;

namespace WebClient.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        }

        /// <summary>
        /// Connect the user to the website
        /// </summary>
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            Customer customer = new Customer();

            // Try to connect the user
            //
            customer.connect(LoginUser.UserName, LoginUser.Password);
            if (customer.IsConnected)
            {
                Session["user"] = customer;
                Server.Transfer("~/Default.aspx");
            }
            else
            {
                Server.Transfer("Login.aspx?failure=true");
            }
        }
    }
}
